package org.example.sdpback.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.example.sdpback.domain.entity.Iteration;
import org.example.sdpback.domain.vo.IterationVO;
import org.example.sdpback.sdk.response.SdpResponseData;
import org.example.sdpback.service.IterationService;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @ProjectName: sdp-back
 * @Package: org.example.sdpback.controller
 * @ClassName: IterationController
 * @Author: zhuxingyue
 * @Description: 迭代接口api
 * @Date: 2024/11/5 18:21
 * @Version: 1.0
 **/
@Tag(name = "迭代管理模块")
@RestController
@RequestMapping("/iteration")
@RequiredArgsConstructor
public class IterationController {
    private final IterationService iterationService;

    @PostMapping("/add")
    @Operation(summary = "添加迭代")
    public SdpResponseData<String> addIteration(Iteration iteration){
        iterationService.saveIteraiton(iteration);
        return SdpResponseData.success();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除迭代")
    public SdpResponseData<String> deleteIteration(Long id){
        iterationService.removeById(id);
        return SdpResponseData.success();
    }

    @PostMapping("/update")
    @Operation(summary = "修改迭代")
    public SdpResponseData<String> updateIteration(Iteration iteration){
        iteration.setUpdateTime(LocalDateTime.now());
        iterationService.updateById(iteration);
        return SdpResponseData.success();
    }

    @GetMapping("/list")
    @Operation(summary = "查询迭代")
    @Parameter(name = "username",description = "创建人")
    public SdpResponseData<List<IterationVO>> listIteration(@RequestParam(required = false) String username){
        List<IterationVO> list = iterationService.getIterationList(username);
        return SdpResponseData.success(list);
    }
}
